<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" id="year">
    <button id="btn">判断</button>
    <input type="text" id="result" disabled>

</body>

<script>
    var yearInp = document.getElementById("year");
    var btn = document.getElementById("btn");
    var resultInp = document.getElementById("result");
    console.log(yearInp, btn, resultInp);
    btn.onclick = function () {
        var year = Number(yearInp.value);
        if (year < 1000 || year > 9999 || year % 1 != 0) {
            alert("请输入1000-9999之间的整数年份。");
            // resultInp.value = year + "请输入1000-9999之间的整数年份";
        } else {
            // console.log("year ok");
            if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                resultInp.value = year + "年为闰年";
            } else {
                resultInp.value = year + "年为平年";
            }
        }

    }

</script>

</html>